﻿#pragma once
#include "Support/rapidjson/JsonIOHandler.h"

class CDXUTDialog;

struct _stGuiProperty
{
	/// 重要属性
	std::wstring UIType;
	std::wstring DialogName;
	int nID;
	/// 文字
	std::wstring	strTextIndex;
	int nFontIndex;	// 字体
	int nTextFormat;	// 左对齐、居中 DT_CENTER | DT_VCENTER;
	std::vector<BYTE> vecTextColor;		// 字体颜色
	/// 纹理
	std::wstring srcPath;
	int nWidth;
	int nHeight;
	int nOffsetX;
	int nOffsetY;
	std::wstring strOrientation;
	/// 状态
	bool bEnable;
	bool bVisible;
	int n4State;	// 四态

	_stGuiProperty() { clear(); }
	void clear()
	{
		UIType = L""; DialogName = L""; nID = 0;
		strTextIndex = L""; nFontIndex = 0; nTextFormat = 0; vecTextColor.clear();
		srcPath = L"";	nWidth = 0; nHeight = 0; nOffsetX = 0; nOffsetY = 0; strOrientation = L"";
		bEnable = true; bVisible = true; n4State = 2;
	}
	bool empty() { return UIType.empty(); }
};

class GuiPropertyReaderHandle :
	public BaseReaderHandler<_stGuiProperty, std::wstring, void>
{
public:
	GuiPropertyReaderHandle(void*);
	bool HandleBool(const std::wstring& key, bool b);
	bool HandleInt(const std::wstring& key, int i);
	bool HandleString(const std::wstring& key, const std::wstring& str);
	bool HandleStartObj(const std::wstring& key);
	bool HandleEndObj();
private:
	HRESULT CreateGUI();
	void SetCommonProperty(CDXUTControl* pControl);
	D3DCOLOR GetPropertyFontColor(const _stGuiProperty* pProperty) const;
	std::wstring m_strDialogName;

	_stGuiProperty m_stGuiProperty;		// 临时的对象,用于向m_list_OperatorPtr中push,不产生栈指针问题
};

struct _FontStruct
{
	WORD fontId;
	std::wstring fontName;
	int fontHeight;
	int fontWeight;
	_FontStruct() { clear(); }
	void clear() { fontId = 0; fontName = L""; fontHeight = 0; fontWeight = 0; }
	bool empty() { return fontName.empty(); }
};

class FontReaderHandle :
	public BaseReaderHandler<_FontStruct, WORD>
{
public:
	FontReaderHandle(std::unordered_map<WORD, _FontStruct>* map);
	bool HandleInt(const std::wstring& key, int i);
	bool HandleStartObj(const std::wstring& key);
	bool HandleEndObj();
private:
	_FontStruct m_FontStruct;		// 临时的对象,用于向m_list_OperatorPtr中push,不产生栈指针问题
};

class Dialog2GuiReaderHandle :
	public BaseReaderHandler<std::wstring, std::wstring>
{
public:
	Dialog2GuiReaderHandle(std::unordered_map<std::wstring, std::wstring>* map) : BaseReaderHandler(map) {}
	bool HandleString(const std::wstring& key, const std::wstring& str);
	bool HandleStartObj(const std::wstring& key){ return true; }
	bool HandleEndObj() { return true; }
};